import {defineStore} from "pinia";
import {reqC1, reqC2, reqC3} from "@/api/product/attr/index.ts";
import {Ref, ref} from "vue";
import type {c1ArrType,ResponseType} from "@/api/product/attr/type.ts";

let useCategory = defineStore("category", () => {
    let c1Arr:Ref<null|c1ArrType[]> = ref(null);
    let c2Arr:Ref<null|c1ArrType[]> = ref(null);
    let c3Arr:Ref<null|c1ArrType[]> = ref(null);
    let c1ID = ref<number | null>(null);
    let c2ID = ref<number | null>(null);
    let c3ID = ref<number | null>(null);
    const getCategory1 = async () => {
        c2ID.value = null;
        c3ID.value = null;
        const result:ResponseType = await reqC1();
        if (result.data.code) {
            c1Arr.value = result.data.data;
        }
    }
    const getC2 = async () => {
        const result:ResponseType = await reqC2(c1ID.value);
        c2Arr.value = result.data.data;
    }
    const getC3 = async () => {
        const result:ResponseType = await reqC3(c2ID.value);
        c3Arr.value = result.data.data;
    }

    return {c1ID,c2ID,c3ID,c1Arr,c2Arr,c3Arr,getCategory1,getC2,getC3};
});
export default useCategory;